package cn.edu.nju.software.cdiy.algorithm.performance;

import cn.edu.nju.software.cdiy.bean.MainBoard;
import cn.edu.nju.software.cdiy.util.Constant;

public class MainBoardEvaluator implements Evaluator<MainBoard>{

	@Override
	public double getPerformance(MainBoard t) {
		double score = 0;
		
		//最大内存得分maxMemScore
		String maxMem = t.getMaxMem().getValue();
		double maxMemScore = getMaxMemBase(maxMem)*Constant.MB_STD_MAXMEM;
		
		//芯片组得分chipSetScore
		int chipSet = t.getChipSet().getKey();
		double chipSetScore = getChipSetBase(chipSet)*Constant.MB_STD_CHIPSET;
		
		//支持内存类型得分compatibleMemScore
		int compatibleMem = t.getCompatibleMEM().getKey();
		double compatibleMemScore = getCompatibleMemBase(compatibleMem)*Constant.MB_STD_COMPATIBLEMEM;
		
		//支持通道模式得分compatibleTunnelScore
		int compatibleTunnel = t.getCompatibleTunnel().getKey();
		double compatibleTunnelScore = getCompatibleTunnelBase(compatibleTunnel)*Constant.MB_STD_COMPATIBLETUNNEL;
		
		score = maxMemScore+chipSetScore+compatibleMemScore+compatibleTunnelScore;
		return score;
	}

	private double getCompatibleTunnelBase(int compatibleTunnel) {
		/*
		 * 支持通道模式基础分
		 * 101双通道			80
		 * 102三通道			90
		 * */
		if(compatibleTunnel==101)
			return 80;
		else return 90;
	}

	private double getCompatibleMemBase(int compatibleMem) {
		/*
		 * 支持内存类型基础分
		 * DDR1			50
		 * DDR2			75
		 * DDR3			100
		 * */
		if(compatibleMem==231)
			return 50;
		else if(compatibleMem==232)
			return 75;
		else if(compatibleMem==233)
			return 100;
		else return 100;
	}

	private double getChipSetBase(int chipSet) {
		/*
		 * 芯片组基础分(待优化)
		 * 13-16,24-33,35-38,44-45		80
		 * 39-43,46,20-23,8-12			90
		 * 1-7,17-19,34,47				100
		 * 
		 * */
		if(chipSet>=1 && chipSet<=7)
			return 100;
		else if(chipSet>=17 && chipSet<=19)
			return 100;
		else if(chipSet==34 || chipSet==47)
			return 100;
		else if(chipSet>=39 && chipSet<=43)
			return 90;
		else if(chipSet==46)
			return 90;
		else if(chipSet>=20 && chipSet<=23)
			return 90;
		else if(chipSet>=8 && chipSet<=12)
			return 90;
		else if(chipSet>=13 && chipSet<=16)
			return 80;
		else if(chipSet>=24 && chipSet<=33)
			return 80;
		else if(chipSet>=35 && chipSet<=38)
			return 80;
		else if(chipSet==44 || chipSet==45)
			return 80;
		else return 90;
	}

	private double getMaxMemBase(String maxMem) {
		/*
		 * 最大内存基础分
		 * 2G			60
		 * 4G			70
		 * 8G			80
		 * 16G			85
		 * 32G			90
		 * 48G			100
		 * */
		if(maxMem.equals("2G"))
			return 60;
		else if(maxMem.equals("4G"))
			return 70;
		else if(maxMem.equals("8G"))
			return 80;
		else if(maxMem.equals("16G"))
			return 85;
		else if(maxMem.equals("32G"))
			return 90;
		else if(maxMem.equals("48G"))
			return 100;
		else return 100;
	}
	
}
